package com.campus.merchant.controller;

import com.campus.common.bean.common.Resp;
import com.campus.merchant.service.MerchantDailyEarningsService;
import com.campus.merchant.vo.earnings.EarningsQueryParam;
import com.campus.merchant.vo.earnings.EarningsRecordVo;
import com.campus.merchant.vo.earnings.EarningsStatisticsVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * <p>
 * 商户每日收益汇总表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-07-11
 */
@RestController
@RequestMapping("/merchantEarnings")
@Api(tags = "商户收益统计")
public class MerchantDailyEarningsController {

    @Autowired
    private MerchantDailyEarningsService merchantDailyEarningsService;

    @GetMapping("/yesterday/{merchantId}")
    @ApiOperation("获取商户昨日收益")
    public Resp<BigDecimal> getYesterdayEarnings(
            @ApiParam("商户ID") @PathVariable Long merchantId) {
        BigDecimal yesterdayEarnings = merchantDailyEarningsService.getYesterdayEarnings(merchantId);
        return Resp.success(yesterdayEarnings);
    }

    @GetMapping("/total/{merchantId}")
    @ApiOperation("获取商户累计收益")
    public Resp<BigDecimal> getTotalEarnings(
            @ApiParam("商户ID") @PathVariable Long merchantId) {
        BigDecimal totalEarnings = merchantDailyEarningsService.getTotalEarnings(merchantId);
        return Resp.success(totalEarnings);
    }

    @GetMapping("/statistics/{merchantId}")
    @ApiOperation("获取商户收益统计")
    public Resp<EarningsStatisticsVo> getEarningsStatistics(
            @ApiParam("商户ID") @PathVariable Long merchantId) {
        EarningsStatisticsVo statistics = merchantDailyEarningsService.getEarningsStatisticsVo(merchantId);
        return Resp.success(statistics);
    }

    @GetMapping("/records")
    @ApiOperation("获取商户收益记录列表")
    public Resp<PageInfo<EarningsRecordVo>> getEarningsRecords(
            @Validated EarningsQueryParam param) {
        PageInfo<EarningsRecordVo> records = merchantDailyEarningsService.getEarningsRecords(param);
        return Resp.success(records);
    }
}
